<#include "../common/scripts.html">
<style>

    .border tbody tr td:nth-child(odd) {
        width: 140px;
    }

    .border tbody tr td:nth-child(even) {
        width: 200px;
    }

    /***隐藏导出按钮**/
    .dt-buttons {
        display: none;
    }

</style>
<div class="page-content detail-content page-content-main" style="height: 650px;">
    <form action="" method="post" id="addForm" class="form-horizontal">
        <input type="hidden" id="postGroupId" value="${postGroup.id}">
        <input type="hidden" id="companyCode" value="${postGroup.companyCode}">
        <div class="fh-subtitle">岗位信息</div>
        <table class="border" style="width: 70%">
            <tr>
                <td>岗位名称</td>
                <td style="position: relative;">
                    <input type="text" value="${postGroup.postName}" class="form-control-gx"
                            maxlength="50" autocomplete="off" readonly/>
                </td>
                <td>岗位编码</td>
                <td style="position: relative;">
                    <input type="text" value="${postGroup.postCode}" class="form-control-gx"
                           maxlength="50" autocomplete="off" readonly/>
                </td>
            </tr>
        </table>
        <div class="fh-subtitle">分配用户
            <span class="btn btn-xs glyphicon glyphicon-plus" onclick="add()">选择</span>
        </div>
        <div style="width:70%!important;padding: 0px;">
            <table id="mainTable" class="eamtable"></table>
        </div>
    </form>

</div>
<script type="text/javascript">
    var dataTable = $("#mainTable");
    $(function () {
        sys.useSimpleRetrieveData();
        var staticPrefix = "${static}";
        var config = sys.DynamicDatabeConfig(staticPrefix, getSearchUrl(), [
            {data: "username", title: "登录名"},
            {data: "name", title: "姓名",},
            {data: "userCode", title: "工号"},
            {
                data: null,
                width:20,
                title: "操作",
                render: function (data) {
                    return getOperHtml(data.userId,data.postGroupId);
                },
            }

        ], true, {ordering: true});

        config.bSort = true;
        config.aLengthMenu = [10,20,50,100];
        //滚动设置
        config.scrollX = true;
        config.autoWidth = true;
        config.scrollY = "60%";
        config.ordering = true;
        dataTable.dataTable(config);
    });

    function getSearchUrl() {
        var url = '/postGroup/ajaxUserPostGroupPage?postGroupId='+$("#postGroupId").val();
        return url;
    }

    function getOperHtml(userId,postGroupId) {
        var  html = '';
        html += '<a onclick="deleteUserPostGroup(\''+userId+'\',\''+postGroupId+'\');return false;" title="删除用户"><i class="fa fa-trash-o iconBtn" style="color: rgb(221, 90, 67)"></i></a>';
        return html;
    }

    function deleteUserPostGroup(userId,postGroupId) {
        sys2.confirm("确定删除该数据吗？", function(){
            sys2.getApiData("deleteUserPostGroup", {
                userId : userId,
                postGroupId:postGroupId
            }, back, "post");
            function back(data) {
                js.showMessage(data.data,"","success",1500)
                dataTable.dataTable().api().ajax.reload(null, false);
            }
        });
    }

    /*********
     * 添加用户
     */
    function add() {
       showLayerWindow(null, "选择用户", "selectUser?postGroupId="+$("#postGroupId").val()+"&companyCode="+$("#companyCode").val(), ['800px', '500px'], ['10px'], false);
    }

    function reload() {
        dataTable.dataTable().api().ajax.reload(null, false);
    }
</script>
